//
//  XGTabBarController.m
//  XGNotifyJump
//
//  Created by 小果 on 16/8/22.
//  Copyright © 2016年 小果. All rights reserved.
//

#import "XGTabBarController.h"
#import "XGBuyCarController.h"
#import "XGHomeViewController.h"
#import "XGRedPacketController.h"
@implementation XGTabBarController

-(void)viewDidLoad{
    [super viewDidLoad];
    
    XGHomeViewController *home = [[XGHomeViewController alloc] init];
    [self addChildVc:home WithTitle:@"首页" andImageName:@"TabBar_HomeBar_Spring"];
    
    XGBuyCarController *buyCar = [[XGBuyCarController alloc] init];
    [self addChildVc:buyCar WithTitle:@"购买" andImageName:@"TabBar_buy"];
    
    XGRedPacketController *redPacket = [[XGRedPacketController alloc] init];
    [self addChildVc:redPacket WithTitle:@"红包" andImageName:@"TabBar_red"];
    
}

/**
 *  添加子控制器的方法
 *
 *  @param ChildVc           子控制器
 *  @param title             标题
 *  @param ImageName         普通状态下的图片
 */
- (void)addChildVc:(UIViewController *)ChildVc WithTitle:(NSString *)title andImageName:(NSString *)ImageName {
    
    UILabel *label = [[UILabel alloc] init];
    label.text = title;
    label.font = [UIFont boldSystemFontOfSize:25];
    label.textColor = [UIColor blueColor];
    CGSize labelS = [label.text sizeWithFont:[UIFont boldSystemFontOfSize:18] maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
    label.frame = CGRectMake(0, 0, labelS.width, labelS.height);
    
    //    ChildVc.title = title;
    
    ChildVc.tabBarItem.title = title;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[UITextAttributeTextColor ] = [UIColor blueColor];
    dict[UITextAttributeFont] = [UIFont boldSystemFontOfSize:15];
    [ChildVc.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    NSMutableDictionary *dict1 = [NSMutableDictionary dictionary];
    dict1[UITextAttributeTextColor] = [UIColor blackColor];
    dict1[UITextAttributeFont] = [UIFont boldSystemFontOfSize:15];
    [ChildVc.tabBarItem setTitleTextAttributes:dict1 forState:UIControlStateNormal];
    // 设置普通状态下的图片
    ChildVc.tabBarItem.image = [UIImage imageNamed:ImageName];
    
    // 设置高亮状态下的图片
    NSString *selectedImageName = [NSString stringWithFormat:@"%@_Sel",ImageName];
    ChildVc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImageName];
    
    // 将每一个子控制器包装成导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ChildVc];
    
    
    // 设置导航栏的标题
    ChildVc.navigationItem.titleView = label;
    
    // 将包装成导航控制器的子控制器添加到当前的控制器中
    [self addChildViewController:nav];
    
}

@end
